home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-05 | 9.6 KB | 274 lines | [TEXT/MPS ] |
- #
- # File: ResEditTest.vu
- #
- # Contains: A ResEdit script that creates a window for each of the predefined resource types.
- # If you have a file called "vu-wants-1-of-each" on the topmost volume, this script
- # will delete it and recreate it. This name is kept in a string called Res_file_name
- # and can be changed if desired.
- #
- # This script does quite a bit so it takes a while to execute. If you would rather
- # have it create some number of resource type windows less than the total, pass a
- # second parameter to create_one_of_each_type() which indicates the number of resource
- # types you'd like created. The following call will create the first 15 resource types:
- #
- # create_one_of_each_type(true,15);
- #
- # The first parameter is reserved for future use. It will be used when the script is
- # extended to actually create resources within the resource type windows.
- #
- # This script demonstrates how to use the scroll command to scroll through a scrolling
- # list of items. Run it and watch what it does with scrolling.
- #
- # Starting Configuration: In order for the script to run properly, the target should be running
- # ResEdit. The active window should be a ResEdit window representing
- # a volume. Key repeat should be turned off.
- #
- # Conventions: Global variables begin with a capital letter.
- #
- # Written by: Jay Jessen
- #
- # Copyright: © 1989 by Apple Computer, Inc., all rights reserved.
- #
- # Change History:
- #
- # 5/15/90 JAS A few formatting changes
- #
- # 6/7/89 Jay created from an old version (optimized scrolling actions)
- #
- # To Do:
- #
-
- # ********************************************************************************************
- # Selects a menu item using the keyboard alias
- task use_keyboard_equiv(alias) begin
- pressKey k: { commandKey };
- type k: { alias };
- releaseKey k: { commandKey };
- end; # end use_keyboard_equiv()
-
-
- # ********************************************************************************************
- # Sets globals for window positioning taking into consideration the target screen size
- task set_screen_dependents() begin
- global Wind_x := 250;# hardwired for now
- global Wind_y := 20;# hardwired for now
- end; # end set_screen_dependents()
-
-
- # ********************************************************************************************
- # Creates a valid resource file
- task create_resource_file(res_file_name) begin
-
- global Volume_name;
-
- if(not match[window t:Volume_name o:1]!) begin
- select [window t:Volume_name]!;
- end;
- select [menuItem title:'New' m:'File']!;
- type keystrokes: { res_file_name };
- select [button title:'OK']!;
- if(match[button t:'OK' w:[window o:1]]!) begin # file already exists
- select [button t:'OK']!;
- select [button t:'Cancel']!;
- clear_file(res_file_name);
- select [menuItem title:'New' m:'File']!;
- type keystrokes: { res_file_name };
- select [button title:'OK']!;
- end;
- end; # end create_resource_file()
-
-
- # ********************************************************************************************
- # Clears a file from Volume window, if check_selection is false it'll clear the current selection
- task clear_file(file_to_clear,check_selection := true) begin
-
- global Volume_name;
-
- if(not match[window t:Volume_name o:1]!) begin
- select [window t:Volume_name]!;
- end;
- if(check_selection) begin
- type k: { "v" };
- found_it := false;
- while not found_it begin
- use_keyboard_equiv("o");
- if(match[staticText t:/The file≈has no resource fork≈Do you wish≈it ∂?/
- w:[window o:1 s:dialog]]!) begin
- select [button t:'Cancel']!;
- type k: { downarrowKey };
- end;
- else begin
- if (((match[window o:1]!).title) = file_to_clear) begin
- found_it := true;
- close [window o:1]!;
- end;
- else begin
- close [window o:1]!;
- type k: { downarrowKey };
- end;
- end;
- end;
- end;
- select [menuItem t:'Clear' m:'Edit']!;
- if match[button t:'OK']! and match[button t:'Cancel']! select [button t:'OK'];
- end;# end clear_file()
-
-
- # ********************************************************************************************
- # Set global values for scroll bar in "Select New Type" dialog
- task set_scroll_bar_globals() begin
-
- global Scrollbar_left,Scrollbar_top,Scrollbar_right,Scrollbar_bottom;
- global Previous_scroller_setting;
-
- select [menuItem title:'New' m:'File']!;
-
- # get the "select new type" dialog's bounding rect and put it in wind_rect
- match [window ord:1 rect:?wind_rect]!;
-
- # get the scroll bar's current setting and rectangle (in local coords)
- current_scroller := match [scrollBar window_owner:[window ord:1]
- setting:?cntrl_value
- rect:?scroller_rect]!;
-
- # compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
- Scrollbar_left := scroller_rect[1];
- Scrollbar_top := scroller_rect[2];
- Scrollbar_right := scroller_rect[3];
- Scrollbar_bottom := scroller_rect[4];
-
- if(cntrl_value[1] = cntrl_value[2]) begin
- global Done_scrolling := true;
- end;
- else begin
- Previous_scroller_setting := cntrl_value;# keep current setting
- end;
- end;# end set_scroll_bar_globals()
-
-
- # ********************************************************************************************
- # Positions a resource type window
- task position_res_type_window() begin
- drag [window ord:1] absolute:{ global Wind_x,global Wind_y };
- Wind_x := Wind_x + 1;
- Wind_y := Wind_y + 2;
- end; # end position_res_type_window()
-
-
- # ********************************************************************************************
- # Scrolls to the next resource type in the "Select New Type" dialog
- task select_next_type() begin
-
- global Previous_scroller_setting,Clicks_for_current_value;
- global Done_scrolling;
- global List_item_height;
- global Scrollbar_left,Scrollbar_top,Scrollbar_right,Scrollbar_bottom;
- global Non_top_item_selection;
-
- scroll [scrollBar w:[window o:1]] absolute: Previous_scroller_setting;
- if(Done_scrolling) begin # ~~ only need to select the remaining visible items (no more scrolling)
- move absolute: { Scrollbar_left - 10,
- Scrollbar_top + ((Non_top_item_selection - 1) * List_item_height) + 5 };
- Non_top_item_selection := Non_top_item_selection + 1;
- end;
- else begin
- move absolute: { Scrollbar_right - 5,Scrollbar_bottom - 5 };
- click;
- match [scrollBar w:[window ord:1] setting:?cntrl_value]!;
- if(cntrl_value[1] = Previous_scroller_setting[1]) begin # scroll value hasn't changed
- Clicks_for_current_value := Clicks_for_current_value + 1;
- for i := 1 to Clicks_for_current_value click;
- end;
- else begin
- Clicks_for_current_value := 0;
- end;
- move absolute: { Scrollbar_left - 10,Scrollbar_top + 5 };
- end;
- click; # Make the new selection
- if (not Done_scrolling) begin
- match [scrollBar w:[window ord:1] setting:?cntrl_value]!;
- Previous_scroller_setting := cntrl_value;
- if (cntrl_value[1] = cntrl_value[2]) begin
- Done_scrolling := true;
- List_item_height :=
- (Scrollbar_bottom - Scrollbar_top) / 7; # 7 is the number of visible types
- Non_top_item_selection := 2; # now used to select remaining visible items
- end;
- end;
- end; # end select_next_type()
-
-
- # ********************************************************************************************
- # Checks for an alert and if one isn't there positions the window, else it logs the alert
- task check_for_alert_or_position_window() begin
- if(match[button w:[window ord:1 style:dialog] t:'OK']!) begin
- text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
- println "dismissing dialog that came up after resource type selection -- static text messages follow:";
- for each m in text_messages println " ∂t",m.t;
- select [button t:'OK'];
- end;
- else begin
- position_res_type_window();
- end;
- end; # end check_for_alert_or_position_window()
-
-
- (****************************************************************************************************
- This task at the very least creates a window for each of the various resource types. If
- suppress_additional_actions is false, the task will call another task (to be determined later)
- which will strip the resource type from the window and call a task that will deal with the given
- type of resource. pass a number to some_of_each if you only a want a certain number of resource
- types created. some_of_each should be 0 if you want all types;
- ****************************************************************************************************)
- task create_one_of_each_type(suppress_additional_actions := true,some_of_each := 0) begin
-
- global Scrollbar_left,Scrollbar_top;
- global Res_file_name;
-
-
- set_scroll_bar_globals();
- move absolute: { Scrollbar_left - 10,Scrollbar_top + 5 };
- click;
- select [button t:'OK']!;
- check_for_alert_or_position_window();
-
- creations_count := 1;
-
- while ((global Non_top_item_selection <> 8) and
- ((not some_of_each) or (creations_count <> some_of_each))) begin
- if(not match[window t:Res_file_name o:1]!) select [window t:Res_file_name]!;
- select [menuItem title:'New' m:'File']!;
- select_next_type();
- creations_count := creations_count + 1;
- select [button t:'OK']!;
- check_for_alert_or_position_window();
- end;
- end; # end create_one_of_each_type() *)
-
-
-
- ##### EXECUTION STARTS HERE ######
-
- Done_scrolling := false;
- Clicks_for_current_value := 0;
-
- Non_top_item_selection := 0;
-
- Res_file_name := "vu-wants-1-of-each";
-
- set_screen_dependents();
-
- match[window o:1 t:?Volume_name]!;
-
- create_resource_file(Res_file_name);
-
- create_one_of_each_type(true,15);
-
- verif_string := "window titles follow for verification";
- println "∂n",verif_string;
- for i := 1 to card(verif_string) print "=";
- println;
-
- for each w in collect[window] println w.title; # ~~~~~~~~ to verify that all the windows were created
-
- clear_file(Res_file_name,false);